<template>
<div class="aa">
  <div class="a">
    <h4>用户账号注册</h4>
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="50px" class="demo-ruleForm">
        <el-form-item  prop="passname">
          <el-input type="username"  v-model="ruleForm.passname " placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item  prop="pass">
          <el-input type="password" v-model="ruleForm.pass"  autocomplete="off" placeholder="8-16位密码，区分大小写"></el-input>
        </el-form-item>
        <el-form-item  prop="checkPass">
          <el-input  type="password" v-model="ruleForm.checkPass"  autocomplete="off" placeholder="请再次确认,8-16位密码，区分大小写"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')" style="width:176px">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
        <div class="bottom">去登陆></div>
      </el-form>
    </div>
  </div>
</template>
<script>
  export default {
    data(){
      var  validatecheckName = (rule, value, callback) => {
        if (value==='') {
          return callback(new Error('用户名不能为空'));
          }else{
            callback();
          }
      };
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.pass) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        ruleForm: {
         passname: '',
         pass: '',
         checkPass: '',
        },
        rules: {
          pass: [
            { validator: validatePass, trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
         passname: [
            { validator:  validatecheckName, trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>
<style>
.aa{
    background-size: 100% 100%;
    background-repeat: no-repeat;
    height: 500px;
    width: 100%;
    background: url("../assets/login1.jpg");
}
.a{
    width: 400px;
    height:270px;
    background-color:#FFFFFF;
    opacity: 0.98;
    display: block;
    position: fixed;
    _position: absolute;
    top: 60%;
    left: 70%;
    margin-left: -400px;
    margin-top: -200px;
    z-index: 10001;
    box-shadow: 2px 2px 4px #DFDBE7;
    padding-top:30px;
    padding-right:50px;
}
.bottom{
    color: #000099;
    margin-left:231px;
}
</style>